<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      visible: false,
      dataFormConfig: {
        id: {
          hidden: true
        },
        trayNo: {
          label: '托盘编号',
          placeholder: '请输入托盘编号'
        },
        traySize: {
          label: '拖盘规格',
          placeholder: '请输入拖盘规格'
        },
        remark: {
          label: '备注',
          inputType: 'textarea',
          placeholder: '请输入备注'
        },
        // productId: {
        //   label: '产品',
        //   type: 'list',
        //   list: [],
        //   placeholder: '请输入产品'
        // },
        // orderDetailId: {
        //   label: '订单',
        //   type: 'list',
        //   list: [],
        //   placeholder: '请输入订单'
        // },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    init(id, property, cb) {
      this.dataForm.id = id || 0
      this.initProductInfoList()
      this.initOrderDetailList()

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('trayNo', 'traySize', 'status', 'productId', 'orderDetailId'),
        initApi: 'trayApi/trayInfoInfo',
        saveApi: 'trayApi/saveTrayInfo',
        updateApi: 'trayApi/updateTrayInfo',
        objectName: 'trayInfo',
        submitCallback: cb
      })

      this.$nextTick(() => {
        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            this.dataForm[key] = property[key]
          })
        }
      })
    }
  }
}
</script>
